package com.example;

import java.util.Arrays;
import java.util.List;

import java.util.Scanner;
import java.util.regex.Pattern;
import static java.util.Arrays.asList;

public class MyClass {

    public static void sword63(){
        char []m = "ABCESFCSADEE".toCharArray();
        char []str = "ABCCED".toCharArray();
        boolean ret = new Solution().hasPath(m,3,4,str);
        System.out.println(ret);
    }
    public static void longestCommonSubstring(){
        String a = "abc";
        String b = "a";
        int ret = new Solution().longestCommonSubstring(a, b);
        System.out.println("ret" + ret);
    }

    public static void sword_mink(){
        int input[] = {4,5,1,6,2,7,3,8};
        List<Integer> result = new Solution().GetLeastNumbers_Solution(input, 4);
        System.out.println(result);
    }

    public static void sword_matrix(){
        int input [][] = {{1,2},{3,4}};
        new Solution().printMatrix(input);
    }

    private static void java8Test(){
        List strList = asList("a", "b", "c");
        long count = strList.stream()
                .filter(str->str.equals("a"))
                .count();
        System.out.println("count " + count);
    }

    static class Meituan{
        public long solution1(long a){
            return fibonacci(a);
        }
        /*        public int fbs(int v, List<Integer> vs){
                    if(vs.size()==v)
                        return v;
                    if ((number == 0) || (number == 1)) {
                        vs.add(number);
                        return number;
                    }else {
                        int sum = fibonacci(number - 1) + fibonacci(number - 2);
                        vs.add(sum);
                    }
                }*/
        public long fibonacci(long number) {
            if ((number == 0) || (number == 1)) {
                return number;
            } else {
                return fibonacci(number - 1) + fibonacci(number - 2);
            }
        }
    }

    public static void main(String[] args){

        Scanner in = new Scanner(System.in);
/*        while(in.hasNext()){
            int i = in.nextInt();
        }*/
        long ret = new Meituan().solution1(3L);
        System.out.println(ret);
    }
    public static void mainbb(String[] args){
        char c = 'b';
        System.out.println('N' +'C');
        System.out.println("hello " + (int)c);
//        int []sample = {2,3,4,2,6,2,5,1};
//        List<Integer> result = new Solution().maxInWindows(sample, 3);
//        System.out.println(result);
//        sword63();
//        sword_mink();

//        java8Test();
//        longestCommonSubstring();
//        AlibabaApril.test();
//        sword_matrix();
//        new Solution().FirstNotRepeatingChar("google");

        /** leetcode */
//        System.out.println(new Leetcode().numSquares(13));
//        List<String> slist = Arrays.asList(new String[]{"hot", "dot", "dog", "lot", "log", "cog"});
//        System.out.println(new Leetcode().ladderLength("hit", "cog", slist));
//        leetcodeTest();
//        addBinary1("101","1");
        testUrl();
//        new LeetCode().
    }

    private static void leetcodeTest(){
        int arr[][] = {{0,0,1,0,0,0,0,1,0,0,0,0,0},
            {0,0,0,0,0,0,0,1,1,1,0,0,0},
            {0,1,1,0,1,0,0,0,0,0,0,0,0},
            {0,1,0,0,1,1,0,0,1,0,1,0,0},
            {0,1,0,0,1,1,0,0,1,1,1,0,0},
            {0,0,0,0,0,0,0,0,0,0,1,0,0},
            {0,0,0,0,0,0,0,1,1,1,0,0,0},
            {0,0,0,0,0,0,0,1,1,0,0,0,0}};
        int m = new Leetcode().maxAreaOfIsland(arr);
        System.out.println(":" + m);
    }


    /**
     * 为什么是一个下标?为什么不是两个?
     */
    public static String addBinary1(String a, String b){
        int lenDiff = a.length() - b.length();
        if(lenDiff < 0){
            String t = a;
            a = b;
            b = t;
            lenDiff = -lenDiff;
        }
        char []arr = new char[lenDiff];
//        Arrays<Character>.fill(arr,'0');
        for (int i = 0; i < arr.length; i++) {
            arr[i] = '0';
        }
        String zeros = new String(arr);
        b = zeros + b;
        System.out.println( "addBinary1: " + b);
        StringBuilder result = new StringBuilder();
        int carry = 0;
        for (int i = a.length() - 1; i >= 0; i++) {
//            if(a.charAt(i))
            int sum = (a.charAt(i) == '1'?1:0) + (b.charAt(i) =='1'?1:0) + carry;
            carry = sum/2;
            sum = sum%2;
            result.append(sum);
        }
        if(carry==1)
            result.append("1");
        System.out.println(result.toString());
        return result.toString();
    }
    private static void testUrl(){
        String url = "J500F_1.08.png";
        final String PROTOCOL = "^((?i:http|https)://)?([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$";
//        if(!Patterns.WEB_URL.matcher(url).matches()){
        boolean ret = (Pattern.compile(PROTOCOL).matcher(url).matches());
//        boolean ret = Patterns.WEB_URL.matcher(url).matches();
        System.out.println("ret" + ret);

    }
}
